const str=[7,1,5,3,6,4]
var maxProfit = function(prices) {
  let minPrice=Infinity
  let maxProfit=0 
  for(let ch of str){
      if(ch<minPrice) minPrice=ch
      maxProfit=Math.max(maxProfit,ch-minPrice)
  }
  return maxProfit
};
console.log(maxProfit(str));
